import Vue from "vue";
import Vuex from "vuex";
import axios from "axios";
Vue.use(Vuex);

export default new Vuex.Store({
  state: {
    banner: [],
    imgUrl: {},
    list: [],
    isLoading: true,
  },
  mutations: {
    SET_BANNER(state, data) {
      state.banner = data;
    },
    SET_RANDOM(state, data) {
      state.imgUrl = data;
    },
    SET_SISTERLIST(state, data) {
      state.list = data;
    },
  },
  actions: {
    getBanners({ commit }) {
      axios({
        method: "GET",
        url: "https://gank.io/api/v2/banners",
      }).then((res) => {
        const { data } = res.data;
        commit("SET_BANNER", data);
      });
    },
    randomNum({ commit }) {
      axios({
        method: "GET",
        url: "https://gank.io/api/v2/random/category/Girl/type/Girl/count/1"
      })
        .then((res) => {
          const { data } = res.data;
          commit("SET_RANDOM", data);
        })
        .catch(() => {
          this.$message.error("内部错误，请刷新重试");
        })
        .finally(() => {
          this.isLoading = false;
        });
    },
    getSisterList({ commit }) {
      axios({
        method: "GET",
        url: "https://gank.io/api/v2/data/category/Girl/type/Girl/page/1/count/20",
      }).then((res) => {
        // console.log(res);
        const { data } = res.data;
        commit("SET_SISTERLIST", data);
      });
    },
  },
  modules: {},
});
